clear all; clc; close all
j = 0;
for n = [3]
j = j + 1;
[z, p, k] = buttap(n);
[b, a] = zp2tf(z, p, k);

[Hn, wn] = freqs(b, a);
H(:, j) = Hn;
w(:, j) = wn;
end
%plot(w, abs(H));xlabel('\omega, rad/s');
%ylabel('|H(j\omega)|');
%legend('n=1','n=3','n=5');
%grid on

Fo = 3e6;
Wo = 2*pi*Fo;
Bw = 2*pi*1e6;
j1 = 0;

[bt, at] = lp2bp(b, a, Wo, Bw);
[Hn, wn] = freqs(bt, at);
Fd = 44.2e6/4; Td = 1/Fd;
[numb, dend] = bilinear(bt, at, Fd);
%[Hn, wn] = freqz(numb, dend);
plot(wn, abs(Hn));xlabel('\omega, rad/s');
%ylabel('|H(j\omega)|');
%legend('n=1','n=3','n=5');
grid on
tmax = 0.001; t = 0:Td:tmax;

N_PRN = 511; T_PRN = 0.001;
PRN = sign(randn(1, N_PRN));
ind_h = fix(mod(t/T_PRN, 1)*N_PRN) + 1;
h = PRN(ind_h);

A = 2;
f0 = 3e6;
phi = pi/4;

u = A * h .* cos(2*pi*f0*t + phi);

S1 = abs(fft(u));
S1 = S1/max(S1);
%plot(fu);
y = filter(numb, dend, u);
%plot(y);

S = abs(fft(y));
S = S/max(S);

plot(20*log10(S))
%yp = ifft(S);
hold on;
plot(20*log10(S1), 'r');

a=1;